public class StringExerciseSolution {
    /**
     * @param inputString
     * @param headLength  the length of string to be trimed from head of the given string
     * @param tailLength  the length of string to be trimed from tail of the given string
     * @return the processed string that get the head and tail part trimmed
     */
    public String trimHeadAndTail(String inputString, int headLength, int tailLength) {
        return inputString.substring(headLength, inputString.length() - tailLength);
    }

    /**
     * @param inputString
     * @return boolean representing whether the head character and tail character of the string is the same
     */
    public boolean ifHeadEqualsTail(String inputString) {
        String head = inputString.substring(0, 1);
        String tail = inputString.substring(inputString.length() - 1, inputString.length());
        if (head.equals(tail))
            return true;
        else
            return false;
    }

    /**
     * @param seg     the string segment to be matched in the target string
     * @param string1
     * @param string2
     * @return
     */
    public boolean ifContainsSameStringSegAtSamePlace(String seg, String string1, String string2) {
        boolean ifSame = false;
        if (string1.indexOf(seg) == string2.indexOf(seg))
            ifSame = true;
        return ifSame;
    }

    public String getTheLongerString(String string1, String string2) {
        return string1.length() > string2.length() ? string1 : string2;
    }

    public String getTheStringWithHigherAlphabeticOrder(String string1, String string2) {
        String result = null;
        if (string1.compareTo(string2) == 0)
            result = string1;
        else if (string1.compareTo(string2) > 0)
            result = string1;
        else
            result = string2;

        return result;
    }

    public static void main(String[] args) {
        StringExerciseSolution se = new StringExerciseSolution();
        System.out.println("Testing Method " +
                "trimHeadAndTail(String inputString, int headLength, int tailLength)");
        System.out.println("Expected Result: CD");
        System.out.println("Actual Result: " + se.trimHeadAndTail("ABCDE", 2, 1));

        System.out.println("-------------");
        System.out.println("Testing Method ifHeadEqualsTail(String inputString)");
        System.out.println("Expected Result: true");
        System.out.println("Actual Result: " + se.ifHeadEqualsTail("SadsfsdS"));
        System.out.println("Expected Result: false");
        System.out.println("Actual Result: " + se.ifHeadEqualsTail("SadH"));

        System.out.println("-------------");
        System.out.println("Testing Method " +
                "ifContainsSameStringSegAtSamePlace(String seg, String string1, String string2)");
        System.out.println("Expected Result: true");
        System.out.println("Actual Result: " + se.ifContainsSameStringSegAtSamePlace("ello", "Jello Rio", "Hello"));
        System.out.println("Expected Result: true");
        System.out.println("Actual Result: " + se.ifContainsSameStringSegAtSamePlace("ello", "Jelo Rio", "Hello"));

        System.out.println("-------------");
        System.out.println("Testing Method getTheLongerString(String string1, String string2)");
        System.out.println("Expected Result: abdsdwe");
        System.out.println("Actual Result: " + se.getTheLongerString("123", "abdsdwe"));

        System.out.println("-------------");
        System.out.println("Testing Method " +
                "getTheStringWithHigherAlphabeticOrder(String string1, String string2)");
        System.out.println("Expected Result: d");
        System.out.println("Actual Result: " + se.getTheStringWithHigherAlphabeticOrder("d", "c"));
    }
}
